<?
	/* View */
	define('PS', 1);
	include_once("../../defines.php");

	include_once('header.php');

	$PageName = 'home';
	include_once(PUBLIC_BEHIND_DIRECTORY . $PageName . '.php');
?>

<script type="text/javascript">
$(function(){
	/*var ChangeBrowserMessage = "Si est&aacute; utilizando Internet Explorer en cualquiera de sus versiones no podr&aacute; visualizar algunas opciones.<br />Se le recomienda descargar <a href='https://www.google.com/chrome/thankyou.html?hl=es&oneclickinstalled=&installdataindex=defaultbrowser' target='_blank'>Google Chrome</a>";
	if (navigator.appName == "Microsoft Internet Explorer"){
		$("#messageIE").html(ChangeBrowserMessage);
	}*/


	var buttons = { previous:$('#jslidernews3 .button-previous'), next:$('#jslidernews3 .button-next') };		
	$('#jslidernews3').lofJSidernews({
		interval : 3000,
	 	easing : 'easeOutBounce',
		direction : 'opacity',
		duration : 30,
		auto : true,
		mainWidth : 980,
		mainHeight : 333,
		navigatorHeight : 83,
		navigatorWidth : 310,
		maxItemDisplay : 4,
		buttons : buttons
	});

	$(".typeNews").click(function(){
		type = parseInt($(this).data("type"));
		if (type == 0)
			page = "interviews.php";
		else
			page = "news.php";
		
		ajaxParams = {
			pageToLoad : "<?=PUBLIC_VIEWS_PATH;?>" + page
		};
		functions.loadSubPage(ajaxParams);
	});

	$("#surveyVote").click(function(){

		option = $("#surveyOption:checked").val();
		$.ajax({
			url : "<?=PUBLIC_CONTROLLERS_PATH;?>" + 'operations.php',
			type : "post",
			dataType : "html",
			data : { 'operation' : 'Vote' , 'controller' : 'surveys', 'survey' : '<?=$Survey->getId();?>', 'option' : option },
			success : function(){
				$('#currentSurvey').html('<div style="min-height:203px;"><?=$messages->getMessage("UserHasVoted");?></div>');
			}
		});
	});
	
	$('.news-open').click(function(){
		$parent = $(this).hasClass('news-open') ? $(this) : $(this).closest('.news-open');
		id = $parent.data('id');
		id = id != undefined ? parseInt(id) : 0;
		readMore(id);
	});
});

	var readMore = function(newsId){
		ajaxParams = {
			pageToLoad : "<?=PUBLIC_VIEWS_PATH . 'news.php';?>",
			parameters : { NewsId :  newsId }
		};
		functions.loadSubPage(ajaxParams);
	};
</script>

<div class="main-column mainHome">
	<!--<div id="messageIE"></div>-->
	<div id="home">
		<div id="jslidernews3" class="lof-slidecontent">
			<div class="preload"><div></div></div>
			<div  class="button-previous">Previous</div>
			<!-- VERTICAL BAR -->
			<div class="navigator-content">
				<div class="navigator-wrapper">
					<ul class="navigator-wrap-inner">
					<?
					foreach($MainNews as $News){
					?>
						<li>
							<div>
								<span class="date dateMain"><?=date("d/m/Y", strtotime($News->getCreated()));?></span>
								<br />
								<h3 class="topNewsTitle"><?=FunctionsHelper::limitText($News->getTitle(), 60);?></h3>
							</div>    
						</li>
					<?
					}
					?>
					</ul>
				</div>
			</div>
			
			<!-- MAIN SLIDER -->
			<div class="main-slider-content">
				<ul class="sliders-wrap-inner">
				<?
				foreach($MainNews as $News){
					$When = $DAYS_OF_WEEK[date("w", strtotime($News->getCreated()))] . " " . date("d", strtotime($News->getCreated())) . ' de ' . $MONTHS[date("n", strtotime($News->getCreated()))] . " de " . date("Y", strtotime($News->getCreated())); 
					$AmountImages = count($News->getImage());
					$Images = $News->getImage();
					$Type = $News->getType() == 1 ? "Noticia" : "Entrevista";
					if ($AmountImages){
						$Selected = 0;
						foreach ($Images as $Image){
							if (empty($Image["tag"])){
								$ImageName = MAIN_IMAGES_NEWS_PATH . $Image["name_file"];
								$Selected = 1;
							}
						}
						if (!$Selected)
							$ImageName = NO_IMAGE;
					}else{
						$ImageName = NO_IMAGE;
					}

				?>
					<li data-path="noticia" data-parameters="id=<?=$News->getId();?>&name=<?=urlencode($News->getUrl());?>">
					
						<img src="<?= $ImageName;?>" title="<?=$News->getTitle();?>" class="topNews" />
						<div class="slider-description">
							<div class="slider-meta">
								<a target="_parent" title="<?=$Type;?>" href="javascript:void(0);" class="typeNews" data-type="<?=$News->getType();?>"><?=$Type;?></a>
							</div>
							<h4><?=$News->getTitle();?></h4>
							<p><?=FunctionsHelper::limitText($News->getSubtitle(), 100);?><br /></p>
							<i class="date"><?=$When;?></i>
						</div>
					</li>
				<?
				}
				?>
				</ul>  	
			</div>
			<div class="button-next">Next</div>
		</div>
		
		<div id="bodyContent">
			<div id="olderNews" class="inlineBlock">
				<div id="olderNewsContent">
					<?
					$counter = 0;

					echo "<div class='news-line double-border-top'>";
					foreach($SecondaryNews as $News){
						$counter++;

						$When = $DAYS_OF_WEEK[date("w", strtotime($News->getCreated()))] . " " . date("d", strtotime($News->getCreated())) . ' de ' . $MONTHS[date("n", strtotime($News->getCreated()))] . " de " . date("Y", strtotime($News->getCreated())); 
						$AmountImages = count($News->getImage());
						$Images = $News->getImage();
						$Type = $News->getType() == 1 ? "Noticia" : "Entrevista";
						if ($AmountImages){
							$Selected = 0;
							foreach ($Images as $Image){
								if (empty($Image["tag"])){
									$ImageName = MAIN_IMAGES_NEWS_PATH . $Image["name_file"];
									$Selected = 1;
								}
									
							}
							if (!$Selected)
								$ImageName = NO_IMAGE;
						}else{
							$ImageName = NO_IMAGE;
						}
						
					?>
						<div class="newsContainer inlineBlock <?echo ($counter % 2 == 0) ? "even " : "odd "; echo (count($SecondaryNews) - $counter < 1) ? "doubleBorderBottom" : "";?>">
							<div class="newsTitle">
								<?=strip_tags(FunctionsHelper::limitText($News->getTitle(), 50));?>
							</div>
							<div class="newsMiniContainer">
								<img src="<?=$ImageName;?>" class="newsMiniImage inlineBlock" />
								<div class="newsMiniText inlineBlock">
									<?=strip_tags(FunctionsHelper::limitTextUntilSpace($News->getText(), 200));?>
									<br />
									<br />
									<span data-path="noticia" data-parameters="id=<?=$News->getId();?>&name=<?=urlencode($News->getUrl());?>" class="moreLink">Ver m&aacute;s &gt;&gt;</span>
								</div>
							</div>
						</div>
					<?
						echo ($counter % 2 == 0) ? "</div>" : "";
						echo ($counter % 2 == 0 && $counter < count($SecondaryNews)) ? "<div class='news-line'>": "";
					}
					if ($counter % 2 == 1){
					?>
						<div class="newsContainer even doubleBorderBottom">
						</div>
					<?
					}
					echo '</div>'; 
					?>
				</div>
			</div>
			<div id="rightContent" class="inlineBlock">			
				<?
				include('rankings.php');
				
				//include('survey.php');
				
				include('social_content.php');
				?>
			</div>
			<div class="clear"></div>
		</div>
	</div>
</div>
<? include('footer.php'); ?>